package com.sunbim.rsrv.params.user;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.sunbim.rsrv.common.validation.StrNoEmpty;
import com.sunbim.rsrv.pojo.User;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiParam;
import lombok.Data;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.multipart.MultipartFile;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.time.LocalDateTime;

@Data
@JsonIgnoreProperties(ignoreUnknown = true)
@Api(value = "json")
public class UserUpdateParams {
    @NotNull(message = "用户id不可为空")
    @ApiModelProperty(value = "用户id", required = true)
    private Integer id;

    @NotBlank(message = "用户名不能为空")
    @ApiModelProperty(value = "用户名")
    private String username;

    @NotBlank(message = "密码不能为空")
    @ApiModelProperty(value = "密码")
    private String password;

    @ApiParam(value = "用户角色")
    private String userRole;

    @ApiModelProperty(value = "昵称")
    private String nickname;

    @ApiModelProperty(value = "区域")
    @NotBlank(message = "区域不能为空")
    private String region;

    @ApiModelProperty(value = "区域等级")
    @NotNull(message = "区域等级不能为空")
    private Integer region_level;

    @StrNoEmpty(message = "项目名称不能为空")
    @ApiModelProperty(value = "项目名称")
    private String project_name;

    @ApiModelProperty(value = "项目描述")
    private String project_desc;

    @ApiModelProperty("项目坐标,字符串格式:\"lng,lat\"")
    private String geo;

    @ApiModelProperty(value = "项目封面")
    private MultipartFile file;


    public User toUser() {
        User user = new User();
        user.setId(this.id);
        user.setUsername(this.username);
        user.setPassword(this.password);
        user.setUserRole(this.userRole);
        user.setNickname(this.nickname);
        user.setRegion(this.region);
        user.setRegionLevel(this.region_level);
        user.setProjectGeo(this.geo);
        user.setProjectName(this.project_name);
        user.setProjectDesc(this.project_desc);
        user.setUpdateTime(LocalDateTime.now());
        return user;
    }
}
